<?php

class Application_Form_Registration extends Zend_Form
{
    public function init()
    {
        $this->setName('reg_form');
        parent::init();
        
        $isEmptyMessage = 'Талаанын сөзсүз толтурулушу зарыл';
        
        $user_login = new Zend_Form_Element_Text('user_login');
        $user_login->setLabel('Логин')
                
                ->setRequired(true)
                ->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $isEmptyMessage)))
                ->addFilter('StringTrim')
                ->addValidator('Db_NoRecordExists', FALSE, array(
                    'table' => 'users',
                    'field' => 'user_login'
                ))
                ->addValidator('Alnum')
                ->setFilters(array('StringToLower'));
        $this->addElement($user_login);
        
        $user_name = new Zend_Form_Element_Text('user_name');
        $user_name->setLabel('Атыңыз:')
                ->setRequired(true)
                ->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $isEmptyMessage)))
                ->addFilter('StringTrim')
                ->addValidator('Alnum');
        $this->addElement($user_name);
        
        $user_surname = new Zend_Form_Element_Text('user_surname');
        $user_surname->setLabel('Фамилияңыз:')
                ->setRequired(true)
                ->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $isEmptyMessage)))
                ->addFilter('StringTrim')
                ->addValidator('Alnum');
        $this->addElement($user_surname);
        
        $user_from = new Zend_Form_Element_Text('user_from');
        $user_from->setLabel('Жайгашкан жериниз:')
                ->setRequired(true)
                ->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $isEmptyMessage)))
                ->addFilter('StringTrim')
                ->addValidator('Alnum');
        $this->addElement($user_from);
        
        $user_password = new Zend_Form_Element_Password('user_password');
        $user_password->setLabel('Сыр сөз:')
                ->setRequired(true)
                ->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $isEmptyMessage)));
        $this->addElement($user_password);
        
        $password_confirm = new Zend_Form_Element_Password('password_confirm');
        $password_confirm->setLabel('Дагы бир жолу киргизиниз:')
                ->setRequired(true)
                ->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $isEmptyMessage)))
                ->addPrefixPath('Asd_Validator', 'Asd/Validator', 'validate')
                ->addValidator('Passwordconfirm');
        $this->addElement($password_confirm);
        
        $user_email = new Zend_Form_Element_Text('user_email');
        $user_email->setLabel('Email')
                ->setRequired(true)
                ->addFilter('StringToLower')
                ->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $isEmptyMessage)))
                ->addValidator('Db_NoRecordExists', FALSE, array(
                    'table' => 'users',
                    'field' => 'user_email'
                ))
                ->addValidator('EmailAddress');
        $this->addElement($user_email);
                
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Каттоодон өтүү')
                ->setAttrib('class', 'button_big');
        $this->addElement($submit);
    }
    
    public function addElement($element, $name = null, $options = null) {
        parent::addElement($element, $name, $options);
        
        if (!isset($name) || $name == null){
            $name = $element->getName();
        }
        
        if (isset($this->_elements[$name])) {
            $this->_elements[$name]->removeDecorator('Label');
            $this->_elements[$name]->removeDecorator('HtmlTag');
            $this->_elements[$name]->removeDecorator('DtDdWrapper');
            $this->_elements[$name]->removeDecorator('Description');
            $this->_elements[$name]->setAttrib('placeholder', $this->_elements[$name]->getLabel());
        }
        
    }
}

